<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var busDictDataGrid;
    $(function() {
        busDictDataGrid = $('#busDictDataGrid').datagrid({
        url : '${path}/admin/busDict/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        idField : 'id',
        sortName : 'description',
        sortOrder : 'desc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [
            {
                width : '50',
                title : '多选',
                field:'ck',
                checkbox:true 
            },
           {
           	 	width : '100',
           	 	title : 'id',
           	 	field : 'id',
                sortable: true,
			}
			,{
           	 	width : '150',
           	 	title : '文字描述',
           	 	field : 'description',
                sortable: true,
			}
			,{
           	 	width : '200',
           	 	title : '后台标识',
           	 	field : 'type',
                sortable: true,
			}
			,{
           	 	width : '100',
           	 	title : '显示标签',
           	 	field : 'label',
                sortable: true,
			}
			,{
           	 	width : '100',
           	 	title : '值',
           	 	field : 'value',
                sortable: true,
			}
			,{
           	 	width : '100',
           	 	title : '排序',
           	 	field : 'hsort',
                sortable: true,

            }
            ,{
                field : 'action',
                title : '操作',
                width : 260,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/admin/busDict/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="busDict-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="busDictEditFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/admin/busDict/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="busDict-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="busDictDeleteFun(\'{0}\');" >删除</a>', row.id);
                    </shiro:hasPermission>
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="busDict-easyui-linkbutton-redis" data-options="plain:true,iconCls:\'fi-refresh icon-yellow\'" onclick="busDictResetRedisFun(\'{0}\');" >刷新REDIS</a>', row.id);
                    return str;
                }
            }

          ] ],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        onLoadSuccess:function(data){
            if(data){
                $.each(data.rows, function(index, item){
                    if(item.checked){
                        $('#contentDataGrid').datagrid('checkRow', index);
                    }
                });
            }
            $('.busDict-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.busDict-easyui-linkbutton-del').linkbutton({text:'删除'});
            $('.busDict-easyui-linkbutton-redis').linkbutton({text:'刷新REDIS'});

        },
        toolbar : '#busDictToolbar'
    });
});

/**
 * 刷新REDIS
 */
function busDictResetRedisFun(id) {
    progressLoad();
    $.post('${path}/admin/busDict/resetRedis', {id : id}, function(result) {
        progressClose();
        parent.$.messager.alert('提示', result.msg, 'info');
    }, 'JSON');
}


    /**
 * 添加框
 * @param url
 */
function busDictAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : "700px",
        height : "300px",
        href : '${path}/admin/busDict/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = busDictDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#busDictAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 编辑
 */
function busDictEditFun(id) {
    if (id == undefined) {
        var rows = busDictDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        busDictDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : "700px",
        height : "300px",
        href :  '${path}/admin/busDict/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = busDictDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#busDictEditForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 删除
 */
 function busDictDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = busDictDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         busDictDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前数据？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/admin/busDict/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     busDictDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}

/**
 * 批量删除
 */
function busDictDeleteIdsFun(){
	var ids = getbusDictSelectionsIds();
 	if(ids.length == 0){
 		$.messager.alert('提示','未选中数据!');
 		return ;
 	}
 	$.messager.confirm('确认','确定删除ID为 '+ids+' 的记录,共'+ids.split(",").length+'记录吗？',function(r){
 	    if (r){
 	    	var params = {"ids":ids};
         	$.post("${path}/admin/busDict/deleteIds",params, function(result){
         		result=JSON.parse(result);
     			if(result.success){
     				parent.$.messager.alert('提示', result.msg, 'info');
                    busDictDataGrid.datagrid('reload');
     			}else{
     				$.messager.alert('错误提示',data.msg);
     			}
     		});
 	    }
 	});
}
/**
 * 获得选中的记录
 */
function getbusDictSelectionsIds(){
	var itemList = $("#busDictDataGrid");
	var sels = itemList.datagrid("getSelections");
	var ids = [];
	for(var i in sels){
		ids.push(sels[i].id);
	}
	ids = ids.join(",");
	sels.length=0;
	return ids;
}

/**
 * 清除
 */
function busDictCleanFun() {
    $('#busDictSearchForm input').val('');
    busDictDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function busDictSearchFun() {
     busDictDataGrid.datagrid('load', $.serializeObject($('#busDictSearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" class="lay_box" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="busDictSearchForm">
            <div class="tab_box">
                <div class="tab_a">
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="busDictSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="busDictCleanFun();">清空</a>
                </div>
                <ul class="list">
					<li>
                        <label>类型:</label>
                        <select id="typeScreen" name="type" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                           <%-- <option value="">请选择</option>
                            <c:forEach items="${busDicts}" var="busDict">
                                <option value="${busDict.type}">${busDict.description}</option>
                            </c:forEach>--%>
                        </select>
                        <script type="text/javascript">
                            $("#typeScreen").combobox({
                                url:'${path}/admin/busDict/busdictlist',
                                valueField:'type',
                                textField:'description',
                                mode : "remote",
                                panelHeight : 300,
                                editable : true,
                                filter :  function(q, row){
                                    var opts = $(this).combobox('options');
                                    return row[opts.textField].indexOf(q) >= 0;
                                }
                            })
                        </script>
                    </li>
                </ul>
            </div>
        </form>
     </div>
 
    <div data-options="region:'center',border:false">
        <table id="busDictDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="busDictToolbar" style="display: none;">
    <shiro:hasPermission name="/admin/busDict/add">
        <a onclick="busDictAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
        <shiro:hasPermission name="/admin/content/deleteIds">
        <a onclick="busDictDeleteIdsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-red'">删除</a>
    </shiro:hasPermission>
</div>